<template>
	<view class="content">
		<view style="margin-bottom: 100upx;">
			<view @click="$backRoute" style="position: fixed; z-index: 10000; left: 20upx;top:25upx; ">
				<image mode="aspectFit" style="width: 50upx;height: 50upx; margin-left: 24upx;" src="/static/img/list/back.png" />
			</view>
			<image mode="widthFix" style="width: 750upx;height: 407upx;" src="/static/img/home/setting/1.png" />
		</view>
<!-- 		<view class="option-box" >
			<view class="option" @click="uploadFile">
				<view class="img">
					<image src="/static/img/home/setting/lanse.png" mode="widthFix"></image>
				</view>
				<text class="txt">Hardware upgrade</text>
			</view>
		</view> -->
		<view class="option-box" >
			<view class="option" @click="naviTo('../../login/lang')">
				<view class="img">
					<image src="/static/img/home/setting/red.png" mode="widthFix"></image>
				</view>
				<text class="txt">{{i18n.msg29  || 'Language'}}  </text>
			</view>
		</view>

		<!-- <view class="option-box">
			<view class="option" @click="selectionClick">
				<view class="img">
					<image src="/static/img/home/setting/huangse.png" mode="widthFix"></image>
				</view>
				<text class="txt">Time zone selection</text>
			</view>
		</view> -->
		<tki-file-manager ref="filemanager" @result="resultPath"></tki-file-manager>
	</view>
</template>

<script>
	import {
		bt_test
	} from "@/api/api.js"

	import tkiFileManager from "@/components/tki-file-manager/tki-file-manager.vue"
	export default {
		data() {
			return {
				// appVersion: ''
				tkiFileManager,
				path: ''
			};
		},
		computed: {
			i18n() {
				return this.$t('message');
			}
		},
		onLoad() {


		},
		onShow() {
			// 导航栏多语言
			//       uni.setNavigationBarTitle({
			//           title: this.i18n.tabBar.me
			//       });

			// 		console.log("onShow")
			// uni.setTabBarItem({
			//     index: 0,
			//     text: this.i18n.tabBar.home,
			// 	fail:(res)=>{
			// 		console.log(111)
			// 	}
			// });
			// uni.setTabBarItem({
			//     index: 2,
			//     text: this.i18n.tabBar.me
			// });
		},
		methods: {
			naviTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			selectionClick() {

				bt_test().then((res) => {
					if (res[1].statusCode == 2100) {
						let data = res[1].data
						console.log(data.byteLength)
					} else {
						uni.showToast({
							title: "接口调用错误",
							icon:"none"
						})
					}
				})

			},
			fileReader: function() {
				const self = this;
				// 请求本地系统文件对象 plus.io.PRIVATE_WWW：应用运行资源目录常量
				plus.io.requestFileSystem(plus.io.PUBLIC_DOCUMENTS, function(fobject) {
					console.log("fs.root是根目录操作对象DirectoryEntry")
					// fs.root是根目录操作对象DirectoryEntry
					fobject.root.getFile('bt_test.bin', {
						create: true
					}, function(fileEntry) {


						fileEntry.file(function(file) {
							let fullPath = fileEntry.fullPath;
							let FileInputStream = plus.android.importClass("java.io.FileInputStream");
							let input = new FileInputStream(file);
							console.log(input)
							let buf = new ArrayBuffer(1024);
							let arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
							let len = input.read(arr);
							input.close();
							console.log(len)
							let bufView = new Uint8Array(buf);
							console.log(arr)
							// 	var fileReader = new plus.io.FileReader();
							// 	self.resInfo = JSON.stringify(file);
							// 	fileReader.readAsText(file);
							// 	fileReader.onloadend = function(evt) {
							// 		// console.log("读取文件成功", JSON.stringify(evt))
							// 		console.log(self.resInfo)


							// 		let str = evt.target.result;
							// 		// let buf = new ArrayBuffer(str.length); // 每个字符占用2个字节
							// 		// let bufView = new Uint8Array(buf);
							// 		// let count = 0;
							// 		// for (let i = 0; i < str.length; i++) {
							// 		// 	bufView[i] = str.charCodeAt(i);
							// 		// 	if(str.charCodeAt(i) > 255){
							// 		// 		count++;
							// 		// 	}
							// 		// }
							// 		// console.log(count)
							// 		// console.log("长度：" + buf.byteLength)
							// 		function mbStringLength(s) {
							// 			var totalLength = 0;
							// 			var i;
							// 			var charCode;
							// 			for (i = 0; i < s.length; i++) {
							// 				charCode = s.charCodeAt(i);
							// 				if (charCode < 0x007f) {
							// 					totalLength = totalLength + 1;
							// 				} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
							// 					totalLength += 2;
							// 				} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
							// 					totalLength += 3;
							// 				}
							// 			}
							// 			//alert(totalLength);
							// 			return totalLength;
							// 		}
							// 		let a = mbStringLength(str)
							// 		console.log(a)

							// 		if (evt.target && evt.target.result) {
							// 			let pos = evt.target.result.indexOf("base64,");
							// 			if (pos !== -1) {
							// 				let base64Str = evt.target.result.substring(pos + "base64,".length)
							// 				let base64 = require('./base64.js').Base64;
							// 				let bin = base64.decode(base64Str)
							// 				console.log(bin)
							// 			}

							// 		}
							// 	}
							// 	self.resInfo = self.resInfo + '--' + file.size + '--' + file.name;
						});
					});
				});
			},
			resultPath(e) {
				this.path = e
				console.log(this.path)
			},
			uploadFile() {
				// let input = document.createElement('input')
				// input.type = 'file'
				// input.onchange = (event) => {
				// 	console.log(event)
				// }
				// input.click();
				// uni.chooseFile({
				// 	count: 6, //默认100
				// 	extension: ['.zip', '.bin'],
				// 	success: function(res) {
				// 		console.log(JSON.stringify(res.tempFilePaths));
				// 	}
				// });
				this.$refs.filemanager._openFile()
				// let sourceType = ['camera', 'album'];
				// uni.chooseImage({
				// 	count: 1,
				// 	sizeType: ['compressed'],
				// 	sourceType: sourceType,
				// 	success: (res) => {
				// 		this.headImg = res.tempFilePaths[0];
				// 		UploadFile('uploadimg', this.headImg, {
				// 			userId: JSON.parse(uni.getStorageSync('userList')).userId
				// 		}).then((res) => {
				// 			let data = JSON.parse(res[1].data);
				// 			if (parseInt(data.errorcode) === 0) {
				// 				uni.setStorageSync("userHead", data.imgURL)
				// 			}
				// 		})
				// 	}
				// });
			},
			gologin() {
				let _this = this;
				uni.showModal({
					title: _this.i18n.popup.exit,
					content: _this.i18n.popup.exittext,
					cancelText: _this.i18n.popup.cancel,
					confirmText: _this.i18n.popup.confirm,
					success: res => {
						if (res.confirm) {
							uni.reLaunch({
								url: '/pages/login/login'
							});
							console.log('用户点击确定');
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	};
</script>

<style>
	.content {
		font-size: 42upx;
		color: #007aff;
	}

	.topttl {
		margin-bottom: 120upx;
		text-align: center;
	}

	.outlogin {
		margin: 0 auto;
		width: 600upx;
		height: 80upx;
		line-height: 80upx;
		text-align: center;
		font-size: 30upx;
		background-color: #007aff;
		color: #fff;
		border-radius: 10upx;
	}

	.option-box {
		margin: 0 auto 80upx;
		padding: 20upx;
		width: 600upx;
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
		border-radius: 10upx;
		border: 2upx solid #bbbbbb;
		box-shadow: 1px 1px 2px 2px rgba(0, 0, 0, 0.1);
		padding-left: 90upx;
	}

	.option-box .option {
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
	}

	.option-box .option .img {
		margin-right: 20upx;
		width: 40upx;
		line-height: 1;
		margin-top: 10upx;
	}

	.option-box .option .img image {
		width: 100%;
		height: auto;
	}

	.option-box .option .txt {
		font-size: 32upx;
	}
</style>
